import { DateTime } from 'luxon'
import { BaseModel, belongsTo, column } from '@adonisjs/lucid/orm'
import type { BelongsTo } from '@adonisjs/lucid/types/relations'
import SalesOrder from '#models/sales_order'
import Goods from '#models/goods'
import Dict from '#models/dict'
import Member from '#models/member'

export default class SalesOrderDetail extends BaseModel {
  /** 销售订单ID */
  @column()
  declare fkSalesOrderId: number

  /** 会员ID */
  @column()
  declare fkMemberId: number | null

  /** 商品ID */
  @column()
  declare fkGoodsId: number | null

  /** 来源ID */
  @column()
  declare fkSourceId: number | null

  /** 单据单号 */
  @column()
  declare billNo: string

  /** 单据日期 */
  @column.dateTime()
  declare billDate: DateTime

  /** 单据Uid */
  @column()
  declare billUid: number

  /** 单据类型 */
  @column()
  declare billType: string

  /** 客户名称 */
  @column()
  declare customerName: string

  /** 正常价格 */
  @column()
  declare normalPrice: number

  /** 数量 */
  @column()
  declare quantity: number

  /** 折扣 */
  @column()
  declare discount: number

  /** 实际价格 */
  @column()
  declare actualPrice: number

  /** 实际支付价格 */
  @column()
  declare actualPayPrice: number

  /** 单据状态 */
  @column()
  declare status: number

  /** 单据备注 */
  @column()
  declare memo: string

  /** 销售单据 */
  @belongsTo(() => SalesOrder)
  declare sales: BelongsTo<typeof SalesOrder>

  /** 商品资料 */
  @belongsTo(() => Goods)
  declare goods: BelongsTo<typeof Goods>

  /** 来源信息 */
  @belongsTo(() => Dict)
  declare source: BelongsTo<typeof Dict>

  /** 会员资料 */
  @belongsTo(() => Member)
  declare member: BelongsTo<typeof Member>
}
